% n=3, no unit roots

function [A, r, p, x]=simul3_10(T)

% I(2) component

w=randn(1,2);

for t=3:T,
    w(t)=2*w(t-1)-w(t-2)+randn;
end

% I(2) component

v=randn(1,2);

for t=3:T,
    v(t)=2*v(t-1)-v(t-2)+randn;
end

% I(2) component

u=randn(1,2);

for t=3:T,
    u(t)=2*u(t-1)-u(t-2)+randn;
end

n=3;

Q=ort(n);
x=Q*[u;v;w];

pmax=6;
BIC=zeros(1,pmax);
    
for p=1:pmax,
    
    [phi_{p}, C_{p}]=reg(x,p);
    
    BIC(p)=log(det(C_{p}))+p*n^2*log(T)/T;
    
end

[mB, p]=min(BIC);

C=C_{p};
phi=phi_{p};


for i=1:n
    for j=1:n
        
        if i==j,
            coef=[1 -phi(i+(0:p-1)*n,j)'];
        else
            coef=[0 -phi(i+(0:p-1)*n,j)'];
        end
        A{j,i}=coef(end:-1:1);


    end
end

F=[phi';eye((p-1)*n) zeros((p-1)*n,n)];

r=eig(F);
    
    
    
